var express = require('express');
var router = express.Router();
var user = require('../model/user');
var title = require('../model/title');
var news = require('../model/new');
var search = require('../model/search');
var video = require('../model/video');
var utils = require('utility');
var fs = require('fs');
var svideo = require('../model/svideo');
var attention = require('../model/attention');
var like = require('../model/like');
var save = require('../model/save');
var comment = require('../model/comment')
//const _filter = {'_id':0,'_v':0}


router.get('/addUser',(req,res)=>{
    var username = req.query.username;
    var password = req.query.password;
    console.log(username,password);
    admin = new user({
        username:username,
        password:password
    })
    admin.save((err,data)=>{
        if(err){
            console.log(err);
            console.log('后台出错了');
        }else{
            res.json({code:0,data:data});
        }
    })

});

router.post('/addUser',(req,res)=>{
    var username = req.body.username;
    var password = req.body.password;
    console.log(username,password);
    admin = new user({
        username:username,
        password:password
    })
    admin.save((err,data)=>{
        if(err){
            console.log(err);
            console.log('后台出错了');
        }else{
            res.json({code:0,data:data});
        }
    })

});
router.post('/getUser',(req,res)=>{
    user.find((err,data)=>{
        if(err){
            console.log('后台出错了');
        }else{
            res.json({code:0,data:data});
        }
    })
});
router.get('/getUser',(req,res)=>{
    user.find((err,data)=>{
        if(err){
            console.log('后台出错了');
        }else{
            res.json({code:0,data:data});
        }
    })
})

//获取标签数据
router.get('/getTitle',(req,res)=>{
    title.find({type:0},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            res.json({statusCode:200,data:data});
        }
    })
});
router.get('/getTitles',(req,res)=>{
    title.find({type:1},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            res.json({statusCode:200,data:data});
        }
    })
});
router.get('/getTitless',(req,res)=>{
    title.find({type:2},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            res.json({statusCode:200,data:data});
        }
    })
});
router.post('/saveTitle',(req,res)=>{
    let id = req.body.id;
    title.findByIdAndUpdate(id,{type:0},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            return res.json({statusCode:200,data:data});
        }
    })
})
router.post('/getNews',(req,res)=>{
    let type = req.body.title;
    let page = req.body.page;
    news.find({page:page,type:type},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,message:'未查到数据'});
            }
            ///var newData = data.filter((item)=>item.isDetele === 0);
            //console.log(newData)
            return res.json({statusCode:200,data:data});
        }
    })
});
router.post('/getNewById',(req,res)=>{
    let id = req.body.id;
    news.find({_id:id},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data === null){
                return res.json({statusCode:200,message:'未查到数据'});
            }
            return res.json({statusCode:200,data:data});
        }
    })
});
router.post('/getKeyByType',(req,res)=>{
    let type = req.body.type;
    search.find({type:type},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,message:'未查到数据'});
            }
            return res.json({statusCode:200,data:data});
        }
    })
});
router.post('/saveKey',(req,res)=>{
    let type = req.body.type;
    let key = req.body.key;
    search.find({key:key,type:type},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //console.log(data);
            if(data.length === 0){
                var admin = new search({
                    key:key,
                    type:type,
                    level:0
                });
                admin.save((err,data)=>{
                    if(err){
                        return res.json({statusCode:500,message:'后台出错了'});
                    }else{
                        return res.json({statusCode:200});
                    }
                })
            }else{
                return res.json({statusCode:200});
            }
        }
    })
});
router.post("/login",(req,res)=>{
    let username = req.body.username;
    let password = req.body.password;
    //console.log(username,password);
    user.find({username:username,password:mymd5(password)},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,message:'未找到用户'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post("/getUsername",(req,res)=>{
    let username = req.body.username;
    user.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,message:'未找到用户'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post('/register',(req,res)=>{
    let username = req.body.username;
    let password = req.body.password;
    var admin = new user({
        username:username,
        password:mymd5(password),
        avatar:"boy",
        nickname:"用户"+username,
        desc:"这个人很懒，什么都没有留下",
        sex:'男',
        birthday:getTime(),
        place:'北京市东城区',
        attentionNum:0
    });
    admin.save((err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            return res.json({statusCode:200,data:data});
        }
    })
});
router.post('/search',(req,res)=>{
    let {title,content} = req.body;
    var query= new RegExp(content, 'i');
    // 模糊查询
    news.find({type:title,title:{$regex:query}},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,status:1});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.get('/deleteHistory',(req,res)=>{
    search.remove({type:2},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            return res.json({statusCode:200,data:data});
        }
    })
});
router.post('/updateNews',(req,res)=>{
    let id = req.body.id;
    news.findByIdAndUpdate(id,{isDetele:1},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            return res.json({statusCode:200,data:data});
        }
    })
});
router.post('/getInfoByUsername',(req,res)=>{
    let username = req.body.username;
    user.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            
            if(data.length === 0){
                return res.json({statusCode:200,message:'未找到用户'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post('/getInfoByUsername1',(req,res)=>{
    let username = req.body.username;
    console.log(username);
    user.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            console.log(data)
            if(data.length === 0){
                return res.json({statusCode:200,message:'未找到用户'});
            }else{
                return res.json({statusCode:200,avatar:data[0].avatar,nickname:data[0].nickname});
            }
        }
    })
});
router.post('/getVideo',(req,res)=>{
    let {type,page} = req.body;
    video.find({type:type,page:page},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,message:'未找到用户'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post('/getSVideo',(req,res)=>{
    let {type,page} = req.body;
    svideo.find({type:type,page:page},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,message:'未找到用户'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post("/getNewsByUsername",(req,res)=>{
    var username = req.body.username
    news.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,message:'未找到数据'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post("/saveNickName",(req,res)=>{
   var {username,nickname} = req.body;
   news.updateMany({username:username},{author:nickname},{ multi: true },(err,data)=>{
       if(err){
            return res.json({statusCode:500,message:'后台出错了'});
       }else{
           user.updateOne({username:username},{nickname:nickname},(err,data)=>{
               if(err){
                return res.json({statusCode:500,message:'后台出错了'});
            }else{
                if(data.length === null){
                    return res.json({statusCode:200,message:'未找到数据'});
                }else{
                    comment.updateMany({username:username},{nickname:nickname},{ multi: true },(err,data)=>{
                        console.log(data);
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data});
                        }
                    })
                    
                }
               }
           })
       }
   })
});
router.post('/saveDesc',(req,res)=>{
    var {username,desc} = req.body;
    user.updateOne({username:username},{desc:desc},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length===0){
                return res.json({statusCode:200,message:'未找到数据'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post('/saveSex',(req,res)=>{
    var {username,sex} = req.body;
    user.updateOne({username:username},{sex:sex},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length===0){
                return res.json({statusCode:200,message:'未找到数据'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post('/saveBirthday',(req,res)=>{
    var {username,birthday} = req.body;
    user.updateOne({username:username},{birthday:birthday},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length===0){
                return res.json({statusCode:200,message:'未找到数据'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post('/savePlace',(req,res)=>{
    var {username,place} = req.body;
    user.updateOne({username:username},{place:place},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length===0){
                return res.json({statusCode:200,message:'未找到数据'});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.post('/isAttention',(req,res)=>{
    var {username,attentionUser} = req.body;
    //console.log(username,attentionUser);
    attention.findOne({username:username,attentionUser:attentionUser},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //console.log(data)
            if(data == null){
                return res.json({statusCode:200,data:0});
            }else{
                return res.json({statusCode:200,data:1});
            }
        }
    })
});
router.post('/isLike',(req,res)=>{
    var {username,newId} = req.body;
    //console.log(username,newId)
    //console.log(username,attentionUser);
    like.findOne({username:username,newId:newId},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
           // console.log(data)
            if(data == null){
                return res.json({statusCode:200,data:0});
            }else{
                return res.json({statusCode:200,data:1});
            }
        }
    })
});
router.post('/isSave',(req,res)=>{
    var {username,newId} = req.body;
    save.findOne({username:username,newId:newId},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //console.log(data)
            if(data == null){
                return res.json({statusCode:200,data:0});
            }else{
                return res.json({statusCode:200,data:1});
            }
        }
    })
});
router.post('/attention',(req,res)=>{
    var {username,attentionUser} = req.body;
    var attentionObj = new attention({
        username:username,
        attentionUser:attentionUser,
    })
    attentionObj.save((err,data1)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //return res.json({statusCode:200,data:data});
            user.findOne({username:attentionUser},(err,data2)=>{
                if(err){
                    return res.json({statusCode:500,message:'后台出错了'});
                }else{
                    var attentionNum = data2.attentionNum;
                    user.updateOne({username:attentionUser},{attentionNum:attentionNum+1},(err,data3)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data3});
                        }
                    })
                }
            })
        }
    })
});
router.post('/cancelAttention',(req,res)=>{
    var {username,attentionUser} = req.body;
    attention.deleteOne({username:username,attentionUser:attentionUser},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data === null){
                return res.json({statusCode:200,message:'未找到数据'});
            }else{
                user.findOne({username:attentionUser},(err,data2)=>{
                    if(err){
                        return res.json({statusCode:500,message:'后台出错了'});
                    }else{
                        var attentionNum = data2.attentionNum;
                        user.updateOne({username:attentionUser},{attentionNum:attentionNum-1},(err,data3)=>{
                            if(err){
                                return res.json({statusCode:500,message:'后台出错了'});
                            }else{
                                return res.json({statusCode:200,data:data3});
                            }
                        })
                    }
                })
            }
        }
    })
});
router.post('/like',(req,res)=>{
    var {username,newId} = req.body;
    var like1 = new like({
        username:username,
        newId:newId,
    });
    like1.save((err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            news.findOne({_id:newId},(err,data)=>{
                if(err){
                    return res.json({statusCode:500,message:'后台出错了'});
                }else{
                    var like = data.like;
                    news.updateOne({_id:newId},{like:like+1},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data});
                        }
                    })
                }
            })
        }
    })
});
router.post('/cancelLike',(req,res)=>{
    var {username,newId} = req.body;
    like.deleteOne({username:username,newId:newId},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            news.findOne({_id:newId},(err,data)=>{
                if(err){
                    return res.json({statusCode:500,message:'后台出错了'});
                }else{
                    var like = data.like;
                    news.updateOne({_id:newId},{like:like-1},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data});
                        }
                    })
                }
            })
        }
    })
});
router.post('/save',(req,res)=>{
    var {username,newId} = req.body;
    var save1 = new save({
        username:username,
        newId:newId,
    });
    save1.save((err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            news.findOne({_id:newId},(err,data)=>{
                if(err){
                    return res.json({statusCode:500,message:'后台出错了'});
                }else{
                    var favorite = data.favorite;
                    news.updateOne({_id:newId},{favorite:favorite+1},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data});
                        }
                    })
                }
            })
        }
    })
});
router.post('/cancelSave',(req,res)=>{
    var {username,newId} = req.body;
    save.deleteOne({username:username,newId:newId},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            news.findOne({_id:newId},(err,data)=>{
                if(err){
                    return res.json({statusCode:500,message:'后台出错了'});
                }else{
                    var favorite = data.favorite;
                    news.updateOne({_id:newId},{favorite:favorite-1},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data});
                        }
                    })
                }
            })
        }
    })
});
router.post('/myNewCount',(req,res)=>{
    var username = req.body.username;
    news.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
           // console.log(data.length)
           return res.json({statusCode:200,data:data.length});
        }
    })
});
router.post('/myAttentionCount',(req,res)=>{
    var username = req.body.username;
    attention.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //console.log(data.length)
           return res.json({statusCode:200,data:data.length});
        }
    })
});
router.post('/myFensiCount',(req,res)=>{
    var username = req.body.username;
    attention.find({attentionUser:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //console.log(data.length)
           return res.json({statusCode:200,data:data.length});
        }
    })
});
router.post('/myhuozanCount',(req,res)=>{
    var username = req.body.username;
    news.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length==0){
                return res.json({statusCode:200,data:0});
            }else{
                var count = 0;
                for(var i = 0;i<data.length;i++){
                    count +=data[i].like
                }
               // console.log(count);
                return res.json({statusCode:200,data:count});
            }
        }
    })
});
router.post('/findAttention',(req,res)=>{
    var username = req.body.username;
    attention.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,count:0});
            }else{
                var arr = [];
                for(var i=0;i<data.length;i++){
                    arr.push(data[i].attentionUser)
                }
                    user.find({username:{$in:arr}},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            res.json({statusCode:200,data:data});
                        }
                    })
            }
        }
    })
});
router.post('/findAttention1',(req,res)=>{
    var username = req.body.username;
    attention.find({attentionUser:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,count:0});
            }else{
                var arr = [];
                for(var i=0;i<data.length;i++){
                    arr.push(data[i].username)
                }
                    user.find({username:{$in:arr}},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            res.json({statusCode:200,data:data});
                        }
                    })
            }
        }
    })
});
router.post('/findSaveList',(req,res)=>{
    var username = req.body.username;
    //console.log(username);
    save.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //console.log(data);
            if(data.length===0){
                return res.json({statusCode:200,count:0});
            }else{
                //console.log(1);
                var arr = [];
                for(var i=0;i<data.length;i++){
                    arr.push(data[i].newId);
                }
                    news.find({_id:{$in:arr}},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data});
                        }
                    })
            }
        }
    })
});
router.post('/findLikeList',(req,res)=>{
    var username = req.body.username;
    //console.log(username);
    like.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            //console.log(data);
            if(data.length===0){
                return res.json({statusCode:200,count:0});
            }else{
                //console.log(1);
                var arr = [];
                for(var i=0;i<data.length;i++){
                    arr.push(data[i].newId);
                }
                    news.find({_id:{$in:arr}},(err,data)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            return res.json({statusCode:200,data:data});
                        }
                    })
            }
        }
    })
});
router.post('/getAvatar',(req,res)=>{
    var username = req.body.username;
    user.findOne({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data===null){
                return res.json({statusCode:500,message:'用户不存在'});
            }else{
                return res.json({statusCode:200,data:data.avatar});
            }
        }
    })
});
router.post('/getAttentionNum',(req,res)=>{
    var username = req.body.username;
    console.log
    user.findOne({username:username},(err,data)=>{
        if(err){
            //console.log(err);
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data===null){
                return res.json({statusCode:500,message:'用户不存在'});
            }else{
                return res.json({statusCode:200,data:data.attentionNum});
            }
        }
    })
});
router.post('/submitComment',(req,res)=>{
    var {username,newId,content,author,avatar,nickname} = req.body;
    //console.log(avatar,nickname);
    news.findOne({_id:newId},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            var comment1 = new comment({
                username:username,
                newId:newId,
                content:content,
                author:author,
                time:getNowDate(),
                avatar:avatar,
                nickname:nickname,
                newsNickname:data.author,
                newsTitle:data.title,
                newsImage:data.images.split("&")[0]
            });
            comment1.save((err,data2)=>{
                if(err){
                    return res.json({statusCode:500,message:'后台出错了'});
                }else{
                    news.findOne({_id:newId},(err,data1)=>{
                        if(err){
                            return res.json({statusCode:500,message:'后台出错了'});
                        }else{
                            var commentNum = data1.comment
                            news.updateOne({_id:newId},{comment:commentNum+1},(err,data)=>{
                                if(err){
                                    return res.json({statusCode:500,message:'后台出错了'});
                                }else{
                                    console.log(data2);
                                    return res.json({statusCode:200,data:data,data2:data2})
                                }
                            })
                        }
                    })
                }
            })
        }
    })
});
router.post('/getComment',(req,res)=>{
    var newId = req.body.newId;
    //console.log(newId);
    comment.find({newId:newId},(err,data1)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data1.length=== 0){
                return res.json({statusCode:200,message:'没有评论'});
            }else{
                return res.json({statusCode:200,data:data1});
            }
        }
    })
});
router.post('/findCommentList',(req,res)=>{
    var username = req.body.username;
    comment.find({username:username},(err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                return res.json({statusCode:200,count:0});
            }else{
                return res.json({statusCode:200,data:data});
            }
        }
    })
});
router.get('/getTotalPage',(req,res)=>{
    news.find((err,data)=>{
        if(err){
            return res.json({statusCode:500,message:'后台出错了'});
        }else{
            if(data.length === 0){
                res.json({statusCode:200,count:0});
            }else{
                var totalPage = data[data.length-1].page;
                res.json({statusCode:200,count:totalPage});
            }
        }
    })
})
function mymd5(pwd){
    var str = 'ywj_is_handsome_%&&8**(())***&hsh8jcnmnjn%%8^^~~~```&^78'
    let salt = utils.md5(utils.md5(pwd+str));
    return salt;
}
function getTime(){
    var data = new Date();
    var y = data.getFullYear();
    var m = data.getMonth()+1;
    var d = data.getDate();
    return y+'-'+m+'-'+d
}
function getNowDate() {
    var date = new Date();
    var sign1 = "-";
    var sign2 = ":";
    var year = date.getFullYear() // 年
    var month = date.getMonth() + 1; // 月
    var day  = date.getDate(); // 日
    var hour = date.getHours(); // 时
    var minutes = date.getMinutes(); // 分
    var seconds = date.getSeconds() //秒
    // 给一位数数据前面加 “0”
    if (month >= 1 && month <= 9) {
     month = "0" + month;
    }
    if (day >= 0 && day <= 9) {
     day = "0" + day;
    }
    if (hour >= 0 && hour <= 9) {
     hour = "0" + hour;
    }
    if (minutes >= 0 && minutes <= 9) {
     minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
     seconds = "0" + seconds;
    }
    var currentdate = year + sign1 + month + sign1 + day + " " + hour + sign2 + minutes + sign2 + seconds
    return currentdate;
   }
module.exports = router
